<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>counter</title>
<script src='./vue.js'></script>
</head>
<body>
<div id="app">
<counter ref="one" @change="handlechange"></counter>
<counter ref="two" @change="handlechange"></counter>
<div>{{total}}</div>
</div>
<script>

Vue.component('counter',{
template:'<div @click="handleadd">{{number}}</div>',
data:function(){
return {number:0}
},
methods:{
handleadd:function(){
this.number++;
this.$emit("change")
}
}
}
)
var vm=new Vue({
el:"#app",
data:{
total:0
},
methods:{
handlechange:function(){
this.total=this.$refs.one.number+this.$refs.two.number;

}
}
})
</script>
</body>